const path = require("path");
const jsonServer = require("json-server");
const router = require("./router");
const db = require("./db")();
const server = jsonServer.create();

const middlewares = jsonServer.defaults({
  static: path.join(__dirname, "../public"),
});

server.use(middlewares);
//req.body
server.use(jsonServer.bodyParser);

router(server);
const jsonRouter = jsonServer.router(db);

//项目api开头
server.use("/api", jsonRouter);

server.listen(8000, () => {
  console.log("JSON SERVER started at 8000");
});
